package edu.spec.pms.dao.impl;

import org.madgecko.basic.dao.BaseDao;
import org.madgecko.basic.model.Pager;
import edu.spec.pms.dao.iface.IRoleDao;
import edu.spec.pms.model.sys.Role;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RoleDao extends BaseDao<Role> implements IRoleDao {

    @Override
    public List<Role> listAllRole() {
        String hql = "from Role";
        return this.list(hql);
    }

    @Override
    public List<Role> listRoleByUser(Integer userId) {
        //TODO 检测sql数量
        String hql = "select ur.role from UserRole ur where ur.user.id=?";
        return this.list(hql, userId);
    }

	@Override
	public Pager<Role> findRoleByCon(Integer status, String con) {
		String hql = " from Role r where 1=1 ";
		if(status!=null){
			hql += " and r.status=" + status;
		}
		if(con!=null && !"".equals(con.trim())){
			hql += " and r.roleName like '%" + con + "%'";
		}
		return this.find(hql);
	}

}
